#include <iostream>
#include <vector>
#include <functional>
#include "common.hpp"
static int gap_t = 0;
static int count=0;
using func_t = std::function<void()>;
std::vector<func_t> funcs;
void Handle(int signal)
{
    for(const auto&func:funcs)
    {
        func();
    }
    alarm(gap_t);
    std::cout<<++count<<std::endl;
}
int main(int argc, char *argv[])
{
    //
    if (argc < 2)
    {
        std::cout << "exe time" << std::endl;
        exit(1);
    }
    gap_t = std::stoi(argv[1]);
    signal(SIGALRM, Handle);
    funcs.reserve(3);
    funcs.emplace_back([]()
                       { std::cout << "刷新内核" << std::endl; });
    funcs.emplace_back([]()
                       { std::cout << "刷新时间片" << std::endl; });
    funcs.emplace_back([]()
                       { std::cout << "切换上下文" << std::endl; });
    std::cout << "定时开始" << std::endl;

    alarm(gap_t);

    while (true)
    {
        sleep(1000);//这里有信号先去处理信号了，进程除了显式忽略或不可中断阻塞（等驱动等）会忽略信号
    }
    return 0;
}